﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sunny.UI;


namespace LaneLpnr.Com
{
    public class Delay
    {
        public static bool Delayms(int milliSecond)
        {
            try
            {
                int start = Environment.TickCount;
                while (Math.Abs(Environment.TickCount - start) < milliSecond)
                {

                    Application.DoEvents();
                }
                return true;
            }
            catch (Exception ex)
            {

                FlashLog.FlashLogger.Debug("异常Delayms" + ex.ToString());
                return false;
            }
        }

        public static bool Delaym_new(int milliSecond)
        {

            try
            {

                // 延时 5 秒弹出对话框
                using (var bg = new BackgroundWorker())
                {
                    bg.DoWork += delegate { System.Threading.Thread.Sleep(milliSecond); };
                    bg.RunWorkerCompleted += delegate
                    {
                        //UIMessageBox.Show("延时时间到");
                        FlashLog.FlashLogger.Info("Delaym_new延时时间到：" + milliSecond);

                    };
                    bg.RunWorkerAsync();
                }
                return true;
            }
            catch (Exception ex)
            {

                FlashLog.FlashLogger.Debug("异常Delaym_new" + ex.ToString());
                return false;
            }
        }




        /// <summary>
        /// 延时函数
        /// </summary>
        /// <param name="delayTime">需要延时多少秒</param>
        /// <returns></returns>
        public static bool Delay_newTime(int delayTime)
        {

            DateTime now = DateTime.Now;
            int s;
            do
            {
                TimeSpan spand = DateTime.Now - now;
                s = spand.Seconds;
                //FlashLog.FlashLogger.Info("获取到秒：" + s + "获取到需要延时得：" + delayTime);
                Application.DoEvents();
            }
            while (s < delayTime);
            FlashLog.FlashLogger.Info("Delay_newTime：" + delayTime);

            return true;
        }





    }
}
